package cleancode.chapter02;

/**
 * @Description
 * @Date 2021/9/20
 * @Created by Jonathan
 */
public class GuessStatisticsMessage {
    private final SemanticProblemDemo01 semanticProblem;
    private String number;
    private String verb;
    private String pluralModifier;

    /**
     * // 调用原来的类里面的某些函数
     *
     * @param semanticProblem 被改造的类
     */
    public GuessStatisticsMessage(SemanticProblemDemo01 semanticProblem) {
        this.semanticProblem = semanticProblem;
    }

    private void thereAreManyLetters(int count) {
        number = Integer.toString(count);
        verb = "are";
        pluralModifier = "s";
    }

    private void thereIsOneLetter() {
        number = "l";
        verb = "is";
        pluralModifier = "";
    }

    private void thereAreNoLetters() {
        number = "no";
        verb = "are";
        pluralModifier = "s";
    }

    private void createPluralDependentMessageParts(int count) {
        /*switch (count) {
            case 0:
                thereAreNoLetters();
                break;
            case 1:
                thereIsOneLetter();
                break;
            default:
                thereAreManyLetters(count);
        }*/
        if (count == 0) {
            thereAreNoLetters();
        } else if (count == 1) {
            thereIsOneLetter();
        } else {
            thereAreManyLetters(count);
        }
    }

    public String make(char candidate, int count) {
        createPluralDependentMessageParts(count);
        return String.format("There %s %s %s%s", verb, number, candidate, pluralModifier);
    }

    public void print(char candidate, int count) {
        semanticProblem.print(make(candidate, count));
    }
}
